<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 1000px;
            height: 100px;
            background-color: #f00;
            margin: 50px auto;
            position: relative;
        }

        .range {
            width: 100px;
            height: 100px;
            position: absolute;
            background-color: green;
            font-size: 50px;
            text-align: center;
            line-height: 100px;
            user-select: none;
            /* pointer-events: none; */
        }
    </style>
</head>

<body>

    <div class="box">
        <div class="range">>></div>
    </div>

    <script>

        var oBox = document.querySelector('.box');
        var oRange = oBox.querySelector('.range');



        var maxWidth = oBox.clientWidth - oRange.offsetWidth;

        // 鼠标按下的时候需要获取鼠标在盒子中的位置
        oRange.onmousedown = function (e) {     // 如果写了pointerEvents小滑块无法绑定事件了  XXXXXXXXXXXXXXXXXXXXXX
            var gapX = e.x;
            // 鼠标移动
            oBox.onmousemove = function (e) {
                var x = e.x - gapX;
                console.log(x);
                if (x < 0) x = 0;
                if (x > maxWidth) x = maxWidth;
                oRange.style.left = x + 'px';
            }

            document.onmouseup = function () {
                oBox.onmousemove = null;
                // 判断
                if (parseInt(oRange.style.left) === maxWidth) {
                    // alert('ok')
                    location.href = '';
                }
                else {
                    oRange.style.left = 0;
                }
            }
        }

    </script>

</body>

</html>